package com.ruoyi.restaurant.service.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import com.ruoyi.restaurant.mapper.SysItemMapper;
import com.ruoyi.restaurant.mapper.SysOrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.restaurant.mapper.SysDiancanMapper;
import com.ruoyi.restaurant.domain.SysDiancan;
import com.ruoyi.restaurant.service.ISysDiancanService;

/**
 * 点餐列Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-04-18
 */
@Service
public class SysDiancanServiceImpl implements ISysDiancanService 
{
    @Autowired
    private SysDiancanMapper sysDiancanMapper;

    /**
     * 查询点餐列
     * 
     * @param diancanId 点餐列主键
     * @return 点餐列
     */
    @Override
    public SysDiancan selectSysDiancanByDiancanId(Integer diancanId)
    {
        return sysDiancanMapper.selectSysDiancanByDiancanId(diancanId);
    }

    /**
     * 查询点餐列列表
     * 
     * @param sysDiancan 点餐列
     * @return 点餐列
     */
    @Override
    public List<SysDiancan> selectSysDiancanList(SysDiancan sysDiancan)
    {
        return sysDiancanMapper.selectSysDiancanList(sysDiancan);
    }

    /**
     * 新增点餐列
     * 
     * @param sysDiancan 点餐列
     * @return 结果
     */
    @Override
    public int insertSysDiancan(SysDiancan sysDiancan)
    {
        String[] itemNamesList = sysDiancan.getItemNamesList();
        List<String> stringItemsList = new ArrayList<>();

        for (int i = 0; i < itemNamesList.length; i ++) {
            stringItemsList.add(itemNamesList[i]);
        }

        for (String i: stringItemsList) {
            sysDiancan.setItemNames(i);
            sysDiancanMapper.insertSysDiancan(sysDiancan);
        }
        return 1;
    }

    /**
     * 计算订单支付的总金额
     *
     * @param sysDiancan
     * @return 结果
     */
    @Override
    public int countOrdersPrice(SysDiancan sysDiancan){
        Integer[] itemPricesList = sysDiancan.getItemPriceList();
        int totalPrice = 0;
        for (int i = 0; i < itemPricesList.length; i ++) {
            totalPrice = totalPrice+itemPricesList[i];
        }
        return totalPrice;
    }

    /**
     * 修改点餐列
     * 
     * @param sysDiancan 点餐列
     * @return 结果
     */
    @Override
    public int updateSysDiancan(SysDiancan sysDiancan)
    {
        return sysDiancanMapper.updateSysDiancan(sysDiancan);
    }

    /**
     * 批量删除点餐列
     * 
     * @param diancanIds 需要删除的点餐列主键
     * @return 结果
     */
    @Override
    public int deleteSysDiancanByDiancanIds(Integer[] diancanIds)
    {
        return sysDiancanMapper.deleteSysDiancanByDiancanIds(diancanIds);
    }

    /**
     * 删除点餐列信息
     * 
     * @param diancanId 点餐列主键
     * @return 结果
     */
    @Override
    public int deleteSysDiancanByDiancanId(Integer diancanId)
    {
        return sysDiancanMapper.deleteSysDiancanByDiancanId(diancanId);
    }
}
